require(['js/util', 'js/form', 'vue', 'js/swiper.jquery.min'], function(Util, Form, Vue, Swiper) {
    var module = {
        $body: $('body')
    };

    var mySwiper;
    var box3Swiper;
    var box6Swiper;
    var box7Swiper;

    var app = new Vue({
        el: '#app',
        data: {
            head_active: '0',
            content: false,
            content_4: false,
            content_7: false,
            content_8_h5: false,
            // 移动端
            menu: false,
            active_02: true
        },
        methods: {
            tabClick: function(type, dom) {
                app.head_active = type;
                if (dom) {
                    $('html, body').animate({ scrollTop: $(dom).offset().top - 100 }, { duration: 500, easing: 'swing' });
                }
                app.menu = !app.menu;
                return false;
            },
            menuClick: function(type) {
                app.menu = !app.menu;
            }
        },
        created: function() {
            var that = this;
        }
    });

    $.extend(module, {
        init: function() {
            this.swiper();
            this.scroll();
            this.resize();
            this.box3Swiper();
            this.box6Swiper();
            this.box7Swiper();
            this.timeLine();
            this.toggleIndexBox2();
        },
        scroll: function() {
            $(window).scroll(function() {
                var wh = $(window).height();
                var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
                if (scrollTop > wh) {
                    app.active_02 = false;
                } else {
                    app.active_02 = true;
                }
            });
        },
        resize: function() {
            var $this = this;
            $(window).resize(function() {
                $this.bannerHeight();
                mySwiper.onResize();
                box3Swiper.onResize();
                box6Swiper.onResize();
                box7Swiper.onResize();
            });
        },
        bannerHeight: function() {
            var $win = $(window);
            var wh = $win.height();
            var ww = $win.width();
            if (ww < 1025) {
                $('#banner_top').css({ paddingTop: '0.92rem', height: '5rem' });
            } else {
                $('#banner_top').css({ paddingTop: 0, height: wh });
            }
        },
        animate1: function() {
            $('#banner2').css('visibility', 'hidden');
            $('#banner3x')
                .removeClass('animated')
                .removeClass('fadeInUp');
            $('#banner4x')
                .removeClass('animated')
                .removeClass('fadeInDown');
            setTimeout(function() {
                $('#banner1').css('visibility', 'visible');
                $('#banner1x')
                    .addClass('animated')
                    .addClass('fadeInRight');
                $('#banner2x')
                    .addClass('animated')
                    .addClass('fadeInLeft');
                $('.banner_top').css('position', 'relative');
            }, 800);
        },
        animate2: function() {
            $('#banner1').css('visibility', 'hidden');
            $('#banner1x')
                .removeClass('animated')
                .removeClass('fadeInRight');
            $('#banner2x')
                .removeClass('animated')
                .removeClass('fadeInLeft');
            setTimeout(function() {
                $('#banner2').css('visibility', 'visible');
                $('#banner3x')
                    .addClass('animated')
                    .addClass('fadeInUp');
                $('#banner4x')
                    .addClass('animated')
                    .addClass('fadeInDown');
            }, 800);
        },
        swiper: function() {
            var $this = this;
            $this.bannerHeight();
            mySwiper = new Swiper('#banner_top', {
                autoHeight: false,
                pagination: '.swiper-pagination',
                paginationClickable: true,
                allowTouchMove: true,
                onInit: function(res) {
                    setTimeout(function() {
                        $('#banner1').css('visibility', 'visible');
                        $('#banner1x')
                            .addClass('animated')
                            .addClass('fadeInRight');
                        $('#banner2x')
                            .addClass('animated')
                            .addClass('fadeInLeft');
                        $('.banner_top').css('position', 'relative');
                    }, 1000);
                },
                effect: 'fade',
                fade: {
                    crossFade: false
                },
                autoplay: 4000,
                onTransitionEnd: function(sp) {
                    if (sp.activeIndex == 0) {
                        $this.animate1();
                    } else {
                        $this.animate2();
                    }
                }
            });
        },
        box3Swiper: function() {
            var $win = $(window);
            var wh = $win.height();
            var ww = $win.width();
            if (ww < 750) {
                box3Swiper = new Swiper('#box3', {
                    slidesPerView: 1,
                    autoplay: 3000, //可选选项，自动滑动
                    centeredSlides: false,
                    spaceBetween: 0,
                    pagination: '.swiper-pagination',
                    paginationClickable: true,
                    loop: true
                });
            } else {
                box3Swiper = new Swiper('#box3', {
                    slidesPerView: 3,
                    autoplay: 0, //可选选项，自动滑动
                    centeredSlides: false,
                    spaceBetween: 0,
                    resistanceRatio : 0,
                    loop: false
                });
            }
            $('#box3')
                .mouseenter(function() {
                    box3Swiper.stopAutoplay();
                })
                .mouseleave(function() {
                    box3Swiper.startAutoplay();
                });
        },
        box6Swiper: function() {
            var $win = $(window);
            var wh = $win.height();
            var ww = $win.width();
            if (ww < 750) {
                box6Swiper = new Swiper('#box6', {
                    slidesPerView: 1,
                    autoplay: 4000, //可选选项，自动滑动
                    centeredSlides: false,
                    spaceBetween: 0,
                    loop: true
                });
                $('#box6')
                    .mouseenter(function() {
                        box3Swiper.stopAutoplay();
                    })
                    .mouseleave(function() {
                        box3Swiper.startAutoplay();
                    });
            }
        },
        box7Swiper: function() {
            var $win = $(window);
            var wh = $win.height();
            var ww = $win.width();
            if (ww < 750) {
                box7Swiper = new Swiper('#box7', {
                    slidesPerView: 1,
                    autoplay: 5000, //可选选项，自动滑动
                    centeredSlides: false,
                    spaceBetween: 16,
                    loop: true
                });
            } else {
                box7Swiper = new Swiper('#box7', {
                    slidesPerView: 4,
                    autoplay: 5000, //可选选项，自动滑动
                    centeredSlides: false,
                    spaceBetween: 16,
                    loop: true
                });
            }

            $('#box7')
                .mouseenter(function() {
                    box7Swiper.stopAutoplay();
                })
                .mouseleave(function() {
                    box7Swiper.startAutoplay();
                });
        },
        toggleIndexBox2:function(){
            $('.icon').click(function () {
                if(this.className.indexOf('icondown')>-1){
                    $(this).removeClass('icondown').addClass('iconup');
                    $(this).next().next().slideUp();
                }else{
                    $(this).removeClass('iconup').addClass('icondown');
                    $(this).next().next().slideDown();
                }
            })
        },
        timeLine: function() {
            var $win = $(window);
            var ww = $win.width();
            $('.inner-round').click(function() {
                var $this = $(this);
                if (this.className.indexOf('active') == -1) {
                    var t = this.innerText;
                    $('.inner-round.active').removeClass('active');
                    $this.addClass('active');
                    if (ww >= 768) {
                        $('.timeline').hide();
                        $('#timeLine' + t).fadeIn();
                    } else {
                        $('.time-axis').hide();
                        $('#timeAxis' + t).fadeIn();
                    }
                }
            });
        }
    });

    module.init();
});
